//
//  XKMineLevelUpController.m
//  XKJY
//
//  Created by xiaokang100 on 2017/2/9.
//  Copyright © 2017年 xiaokang100. All rights reserved.
//

#import "XKMineLevelUpController.h"
#import "XKMineLevelUpConfirmController.h"


static NSString *const XKMineLevelUPCell = @"XKMineLevelUPCell";


@interface XKMineLevelUpController ()

@end

@implementation XKMineLevelUpController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initTableView];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:YES];
}

#pragma mark - 初始化TableView
- (void)initTableView {
    self.tableView.rowHeight = 50*Scale_H;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
    self.tableView.separatorInset = UIEdgeInsetsMake(0, 0, 0, 0);
    self.tableView.bounces = NO;
}


#pragma mark - UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (self.currentLevel.integerValue == 1) {
        return 3;
    } else if (self.currentLevel.integerValue == 2) {
        return 2;
    } else if (self.currentLevel.integerValue == 3) {
        return 1;
    } else {
        return 0;
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:XKMineLevelUPCell];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:XKMineLevelUPCell];
    }
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    if (self.currentLevel.integerValue == 1) {
        NSArray *arr = @[@"小康会员", @"消费商",@"金牌消费商"];
        cell.textLabel.text = arr[indexPath.row];
    } else if (self.currentLevel.integerValue == 2) {
        NSArray *arr = @[@"消费商",@"金牌消费商"];
        cell.textLabel.text = arr[indexPath.row];
    } else if (self.currentLevel.integerValue == 3) {
        cell.textLabel.text = @"金牌消费商";
    }
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 10*Scale_H;
}

#pragma mark - UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    
    if (self.currentLevel.integerValue == 1) {
        if (indexPath.row == 0) {
            [self pushViewControllerWithType:LEVELUP_TYPE_ONE];
        } else if (indexPath.row == 1) {
            [self pushViewControllerWithType:LEVELUP_TYPE_TWO];
        } else if (indexPath.row == 2) {
            [self pushViewControllerWithType:LEVELUP_TYPE_THREE];
        }
        
    } else if (self.currentLevel.integerValue == 2) {
        if (indexPath.row == 0) {
            [self pushViewControllerWithType:LEVELUP_TYPE_TWO];
        } else if (indexPath.row == 1) {
            [self pushViewControllerWithType:LEVELUP_TYPE_THREE];
        }
        
    } else if (self.currentLevel.integerValue == 3) {
        [self pushViewControllerWithType:LEVELUP_TYPE_THREE];
    }
    
    

    
}

- (void)pushViewControllerWithType:(LEVELUP_TYPE)type {
    XKMineLevelUpConfirmController *confirmVC = [XKMineLevelUpConfirmController new];
    NSString *titleString;
    switch (type) {
        case 1:titleString = @"升级小康会员";break;
        case 2:titleString = @"升级消费商";break;
        case 3:titleString = @"升级金牌消费商";break;
        default:break;
    }
    confirmVC.title = titleString;
    confirmVC.level = type;
    confirmVC.levelUPType = self.levelUPType;
    [self.navigationController pushViewController:confirmVC animated:YES];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
